<html>
    <head>
    <link rel="stylesheet" href="lmm.css" type="text/css" />
    </head>
<body class="lmm">
<!-- This file is part of the Lisp Machine Manual.  -*-Text-*- -->
<!-- Function Description: Other Predicates. -->

	The following functions are some other general purpose predicates.

<div class='defun' id='eq'>
  <font class='exdent'>
    <font class='funcname'>eq </font>
    <font class='italic' color='purple'>x y</font>
  </font><br>
<!-- open: 1, close: 0 --><font class="lisp">(eq <!-- open: 2, close: 0 --><font class="italic">x y</font><!-- open: 2, close: 1 -->) =&gt; t</font><!-- open: 2, close: 2 --> <!-- MATCHED MATCHED MATCHED --> if and only if <!-- open: 3, close: 2 --><font class="italic">x</font><!-- open: 3, close: 3 --> <!-- MATCHED MATCHED MATCHED --> and <!-- open: 4, close: 3 --><font class="italic">y</font><!-- open: 4, close: 4 --> <!-- MATCHED MATCHED MATCHED --> are the same object.
It should be noted that things that print the same are not necessarily <!-- open: 5, close: 4 --><font class="lisp">eq</font><!-- open: 5, close: 5 --> <!-- MATCHED MATCHED MATCHED --> to each other.
In particular, numbers with the same value
need not be <!-- open: 6, close: 5 --><font class="lisp">eq</font><!-- open: 6, close: 6 --> <!-- MATCHED MATCHED MATCHED -->, and two similar lists are usually not <!-- open: 7, close: 6 --><font class="lisp">eq</font><!-- open: 7, close: 7 --> <!-- MATCHED MATCHED MATCHED -->.
<p class='cindent'><!-- "eq versus equal" -->
<pre class='lisp'>
<font class='exdent'>Examples:
</font><!-- exdent -->(eq 'a 'b) =&gt; nil
(eq 'a 'a) =&gt; t
(eq (cons 'a 'b) (cons 'a 'b)) =&gt; nil
(setq x '(a . b)) (eq x x) =&gt; t
</pre>
Note that in Lisp Machine Lisp equal fixnums are <!-- open: 8, close: 7 --><font class="lisp">eq</font><!-- open: 8, close: 8 --> <!-- MATCHED MATCHED MATCHED -->; this is not true in Maclisp.
Equality does not imply <!-- open: 9, close: 8 --><font class="lisp">eq</font><!-- open: 9, close: 9 --> <!-- MATCHED MATCHED MATCHED -->-ness for other types of numbers.
</div>

<div class='defmac' id='neq x y'><font class='exdent'><font class='funcname' id='neq x y'>neq x y</font><font class="italic"> Macro</font></br></font><!-- end font_exdent --><!-- open: 10, close: 9 --><font class="lisp">(neq <!-- open: 11, close: 9 --><font class="italic">x y</font><!-- open: 11, close: 10 -->)</font><!-- open: 11, close: 11 --> <!-- MATCHED MATCHED MATCHED --> = <!-- open: 12, close: 11 --><font class="lisp">(not (eq <!-- open: 13, close: 11 --><font class="italic">x y</font><!-- open: 13, close: 12 -->))</font><!-- open: 13, close: 13 --> <!-- MATCHED MATCHED MATCHED -->.  This is provided
simply as an abbreviation for typing convenience.
</div>

<div class='defun' id='equal'>
  <font class='exdent'>
    <font class='funcname'>equal </font>
    <font class='italic' color='purple'>x y</font>
  </font><br>
The <!-- open: 14, close: 13 --><font class="lisp">equal</font><!-- open: 14, close: 14 --> <!-- MATCHED MATCHED MATCHED --> predicate returns <!-- open: 15, close: 14 --><font class="lisp">t</font><!-- open: 15, close: 15 --> <!-- MATCHED MATCHED MATCHED --> if its arguments are similar
(isomorphic) objects. (cf. <!-- open: 16, close: 15 --><font class="lisp">eq</font><!-- open: 16, close: 16 --> <!-- MATCHED MATCHED MATCHED -->)
<p class='cindent'><!-- "eq versus equal" -->
Two numbers are <!-- open: 17, close: 16 --><font class="lisp">equal</font><!-- open: 17, close: 17 --> <!-- MATCHED MATCHED MATCHED --> if they have the same value (a flonum
is never <!-- open: 18, close: 17 --><font class="lisp">equal</font><!-- open: 18, close: 18 --> <!-- MATCHED MATCHED MATCHED --> to a fixnum though).
Two strings are <!-- open: 19, close: 18 --><font class="lisp">equal</font><!-- open: 19, close: 19 --> <!-- MATCHED MATCHED MATCHED --> if they have the same length,
and the characters composing them are the same.  Alphabetic case is ignored.
For conses, <!-- open: 20, close: 19 --><font class="lisp">equal</font><!-- open: 20, close: 20 --> <!-- MATCHED MATCHED MATCHED --> is defined recursively as
the two <!-- open: 21, close: 20 --><font class="lisp">car</font><!-- open: 21, close: 21 --> <!-- MATCHED MATCHED MATCHED -->'s being <!-- open: 22, close: 21 --><font class="lisp">equal</font><!-- open: 22, close: 22 --> <!-- MATCHED MATCHED MATCHED --> and the two <!-- open: 23, close: 22 --><font class="lisp">cdr</font><!-- open: 23, close: 23 --> <!-- MATCHED MATCHED MATCHED -->'s being equal.
All other objects are <!-- open: 24, close: 23 --><font class="lisp">equal</font><!-- open: 24, close: 24 --> <!-- MATCHED MATCHED MATCHED --> if and only if they are <!-- open: 25, close: 24 --><font class="lisp">eq</font><!-- open: 25, close: 25 --> <!-- MATCHED MATCHED MATCHED -->.
Thus <!-- open: 26, close: 25 --><font class="lisp">equal</font><!-- open: 26, close: 26 --> <!-- MATCHED MATCHED MATCHED --> could have been defined by:
<pre class='lisp'>
(defun equal (x y)
       (or (eq x y)
	   (and (numberp x) (numberp y) (= x y))
	   (and (stringp x) (stringp y) (string-equal x y))
	   (and (listp x)
		(listp y)
		(equal (car x) (car y))
		(equal (cdr x) (cdr y))))) 
</pre>

As a consequence of the above definition, it can be seen that
<!-- open: 27, close: 26 --><font class="lisp">equal</font><!-- open: 27, close: 27 --> <!-- MATCHED MATCHED MATCHED --> need not terminate when applied to looped list structure. 
In addition, <!-- open: 28, close: 27 --><font class="lisp">eq</font><!-- open: 28, close: 28 --> <!-- MATCHED MATCHED MATCHED --> always implies <!-- open: 29, close: 28 --><font class="lisp">equal</font><!-- open: 29, close: 29 --> <!-- MATCHED MATCHED MATCHED -->; that is, if <!-- open: 30, close: 29 --><font class="lisp">(eq a b)</font><!-- open: 30, close: 30 --> <!-- MATCHED MATCHED MATCHED -->
then <!-- open: 31, close: 30 --><font class="lisp">(equal a b)</font><!-- open: 31, close: 31 --> <!-- MATCHED MATCHED MATCHED -->.  An intuitive definition of <!-- open: 32, close: 31 --><font class="lisp">equal</font><!-- open: 32, close: 32 --> <!-- MATCHED MATCHED MATCHED --> (which is
not quite correct) is that two objects are <!-- open: 33, close: 32 --><font class="lisp">equal</font><!-- open: 33, close: 33 --> <!-- MATCHED MATCHED MATCHED --> if they look the
same when printed out.  For example:
<pre class='lisp'>
(setq a '(1 2 3))
(setq b '(1 2 3))
(eq a b) =&gt; nil
(equal a b) =&gt; t
(equal "Foo" "foo") =&gt; t
</pre>
</div>

<div class='defun' id='not'>
  <font class='exdent'>
    <font class='funcname'>not </font>
    <font class='italic' color='purple'>x</font>
  </font><br>
</div><div class='defun1' id='null'>
<font class='exdent'><font class='funcname'>null </font><font class='italic' color='purple'>x
</font></font><br>	<!-- open: 34, close: 33 --><font class="lisp">not</font><!-- open: 34, close: 34 --> <!-- MATCHED MATCHED MATCHED --> returns <!-- open: 35, close: 34 --><font class="lisp">t</font><!-- open: 35, close: 35 --> <!-- MATCHED MATCHED MATCHED --> if <!-- open: 36, close: 35 --><font class="italic">x</font><!-- open: 36, close: 36 --> <!-- MATCHED MATCHED MATCHED --> is <!-- open: 37, close: 36 --><font class="lisp">nil</font><!-- open: 37, close: 37 --> <!-- MATCHED MATCHED MATCHED -->, else <!-- open: 38, close: 37 --><font class="lisp">nil</font><!-- open: 38, close: 38 --> <!-- MATCHED MATCHED MATCHED -->.
<!-- open: 39, close: 38 --><font class="lisp">null</font><!-- open: 39, close: 39 --> <!-- MATCHED MATCHED MATCHED --> is the same as <!-- open: 40, close: 39 --><font class="lisp">not</font><!-- open: 40, close: 40 --> <!-- MATCHED MATCHED MATCHED -->; both functions are included for the sake
of clarity.  Use <!-- open: 41, close: 40 --><font class="lisp">null</font><!-- open: 41, close: 41 --> <!-- MATCHED MATCHED MATCHED --> to check whether something is <!-- open: 42, close: 41 --><font class="lisp">nil</font><!-- open: 42, close: 42 --> <!-- MATCHED MATCHED MATCHED -->; use <!-- open: 43, close: 42 --><font class="lisp">not</font><!-- open: 43, close: 43 --> <!-- MATCHED MATCHED MATCHED -->
to invert the sense of a logical value.  Even though Lisp uses the symbol
<!-- open: 44, close: 43 --><font class="lisp">nil</font><!-- open: 44, close: 44 --> <!-- MATCHED MATCHED MATCHED --> to represent falseness, you shouldn't make understanding of your program
depend on this fortuitously.  For example, one often writes:
<pre class='lisp'>
(cond ((not (null lst)) ... )
      ( ... ))
<!-- open: 45, close: 44 --><font class="main">rather than</font><!-- open: 45, close: 45 --> <!-- MATCHED MATCHED MATCHED -->
(cond (lst ... )
      ( ... ))
</pre>
	There is no loss of efficiency, since these will compile into exactly
the same instructions.
</div>
<!-- eof -->
</body>
</html>

